package com.yiboshi.rehrs.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yiboshi.rehrs.common.Decrypt;
import com.yiboshi.rehrs.common.VarConstant;
import com.yiboshi.rehrs.config.RehrsSystemConfig;
import com.yiboshi.rehrs.config.ThreadLocalSession;
import com.yiboshi.rehrs.domain.entity.*;
import com.yiboshi.rehrs.domain.service.IInviteRecordService;
import com.yiboshi.rehrs.domain.service.IRechargeCardService;
import com.yiboshi.rehrs.domain.service.IZhongUserImageService;
import com.yiboshi.rehrs.domain.service.IZhongUserService;
import com.yiboshi.rehrs.exception.ZyantExceptionUtils;
import com.yiboshi.rehrs.helper.*;
import com.yiboshi.rehrs.manager.ZhongYouManager;
import com.yiboshi.rehrs.param.*;
import com.yiboshi.rehrs.util.*;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;

/**
 * 方法格式固定，第一个参数是版本 第二个参数ZhongReq
 * @author jack 2025/3/21
 */
@RestController
@RequestMapping({"/zh/api/user/{version}/","/smf/user/{version}"})
@Slf4j
public class AntZhongController {


    @Qualifier("HelperZhong_1")
    @Autowired
    HelperXiaofei helperXiaofei;

    @Autowired
    @Qualifier("HelperZhong_2")
    HelperDaxiang helperDaxiang;


    @Autowired
    @Qualifier("HelperZhong_3")
    HelperJinshe helperJinshe;


    @Autowired
    StringRedisTemplate stringRedisTemplate;



    @Autowired
    RedisHelper redisHelper;

    @Autowired
    IRechargeCardService rechargeCardService;


    @Autowired
    RedisLocker redisLocker;

    @Autowired
    IZhongUserService zhongUserService;
    @Autowired
    IZhongUserImageService zhongUserImageService;
    @Autowired
    ZhongYouManager zhongYouManager;

    @Autowired
    IInviteRecordService inviteRecordService;

    @Autowired
    LimitHelper limitHelper;





    //登录
    @ApiOperation(value = "1.0 logon", httpMethod = "POST", notes = "1.0 登录", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("logon")
    public ZhongRes<Map> logon(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        Integer integer = Integer.valueOf(version);
        if(integer<128&&!AperStringUtils.hitNumber(3)){
            return VarConstant.need_update_res;
        }
        String account = zhongReq.getAccount();
        log.info("logon account:{}",account);
        ZhongUser zhongUser = zhongUserService.one(account);
        String imei = zhongReq.getImei();
        if(zhongUser!=null&&StrUtils.isBlank(imei)){
            imei = zhongUser.getImei();
        }
        if(StrUtils.isBlank(imei)){
            imei = "867382035888381";
        }
        zhongReq.setImei(imei);
        //zhongUser = null;//redisHelper.loadSessionUserByAccount(zhongReq.getAccount(),true);
        HelperZhong helperZhong ;
        helperZhong = redisHelper.selectHelper();
        ZyantExceptionUtils.x(helperZhong==null,"授权异常,请稍后再试");
        //helperZhong = helperJinshe;
        //helperZhong = helperDaxiang;
        log.info("selectHelper mode:{} ,account:{},type:{}",helperZhong.getMode(),account,
                zhongReq.getType()
        );
        Map<String, String> stringMap = null;
        try{
            //zhongReq.setImei("");
            stringMap  = helperZhong.logonHeader(zhongReq);
        }catch (Exception e){
            log.info("",e);
        }
        int type = CollUtil.isEmpty(stringMap)?0:1;
        //redisHelper.increase(helperZhong.getMode(),type);
        ZyantExceptionUtils.x(type==0,"授权异常,请稍后再试-"+helperZhong.getMode());
        //helperJinshe.logonHeaderNew(zhongReq)

        if( helperZhong == helperJinshe){
            stringMap.put("dlv_equipment_type","Newland");
            stringMap.put("user-agent","Dalvik/2.1.0 (Linux; U; Android 9;NLS-MT90 Build/PQ3A.190801.002)");
            stringMap.put("pda_sys_version","10");
            stringMap.put("pda_id",imei);
        }
        //pda_id: 869296041015581 金蛇
        stringMap.put("pda_id","869296041015581");
        log.info("type:{},header:{}",type,stringMap);
        return ZhongRes.ok(stringMap);

    }

    //登录
    @ApiOperation(value = "2.0 logon", httpMethod = "POST", notes = "2.0 登录成功回传数据，返回成功才算登录成功,obj=1需要回传图片", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("logon/back")
    public ZhongRes<Letter> logonBack(@PathVariable String version, @RequestBody() ZhongReq<ZhongUser> zhongReq) {
        String originData = zhongReq.getOriginData();
        ZhongUser zhongUser = JSON.parseObject(originData, ZhongUser.class);
        zhongUser.setMode(0);
        String account = zhongUser.getAccount();
        if(StrUtils.isBlank(account)||account.length()<4){
            return ZhongRes.fail("account is error");
        }
        String token = zhongUser.getToken();
        if(StrUtils.isBlank(token)){
            return ZhongRes.fail("token is error");
        }
        ZhongUser zhongUserDB = zhongUserService.one(account);
        if(zhongUserDB==null){
            zhongUserDB = zhongUser;
            zhongUserDB.setImei("867382035888381");
            zhongUserDB.setPadId("867382035888381");
            zhongUserService.saveOrUpdateUser(zhongUserDB);
            //zhongUserDB = zhongUser;
        }
        zhongUserDB.setToken(token);
        //zhongUser.setMode(0);
        //zhongUser.setVipExpDate(null);
        redisHelper.saveSessionUser(zhongUserDB,true);

        //发放登录后的sauth
        LocalDateTime vipExpDate = zhongUserDB.getVipExpDate();
        Letter letter = null;
        if(vipExpDate!=null&&vipExpDate.isAfter(LocalDateTime.now())){
            String sAuth = limitHelper.getSAuth(account,0);
            String newHost = "";
            letter = new Letter();
            letter.setApiHost(newHost);
            letter.setSauth(sAuth);
        }
        //登录成功后 同步token
        int hour = LocalDateTime.now().getHour();
        if(hour<=6&&hour>=5){
            ThreadPoolUtils.submitTask(()->{
                redisHelper.addYuyueToken(account,token);
            });
        }
        //监测异常账号登录
        return ZhongRes.ok(letter);
    }


    @ApiOperation(value = "3.0 logon", httpMethod = "POST", notes = "3.0 图片回传，可以异步", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("logon/back/image")
    @Decrypt(value = false)
    public ZhongRes logonBackImage(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        return ZhongRes.ok();
       /* try{
            ZhongUser zhongUser = redisHelper.loadSessionUser(zhongReq.getToken());
            if(zhongUser!=null){
                zhongReq.setAccount(zhongUser.getAccount());
                zhongUserService.saveOrUpdateUserFace(zhongReq);
            }
        }catch (Exception e){
            log.info("",e);
        }

        ZhongRes ok = ZhongRes.ok();
        return ok;*/
    }

    @ApiOperation(value = "3.1 退出登录", httpMethod = "POST", notes = "3.1 退出登录", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("logon/out")
    public ZhongRes logonOut(@PathVariable String version, @RequestBody() ZhongReq<LogonOut> zhongReq) {
        String token = zhongReq.getToken();
        if(StrUtils.isBlank(token)){
            return ZhongRes.fail("");
        }
        ZhongUser zhongUser = redisHelper.loadSessionUser(token,true);
        if(zhongUser==null){
            return ZhongRes.ok();
        }
        redisHelper.delSessionUserToken(token,zhongUser.getAccount(),true);
        return ZhongRes.ok();
    }







    @ApiOperation(value = "5.0 further", httpMethod = "POST", notes = "5.0 业务操作", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping({"further","vip"})
    public ZhongRes<Map> vip(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        ZhongUser zhongSessionUser = redisHelper.loadSessionUser(zhongReq.getToken(),true);
        if (zhongSessionUser==null) {
            return VarConstant.need_login_res;
        }
        //ZhongUser one = zhongUserService.one(zhongSessionUser.getAccount());
        Integer mode = zhongSessionUser.getMode();
        LocalDateTime vipExpDate = zhongSessionUser.getVipExpDate();
        if(checkVip(vipExpDate, mode)){
            return ZhongRes.fail("请先激活VIP");
        }
        HelperZhong helperZhong = helperXiaofei;
        helperZhong = redisHelper.selectHelper(zhongReq.getType());
        //helperZhong = helperDaxiang;

        log.info("vipHeader account:{} mode:{} type:{} ",zhongSessionUser.getAccount(),helperZhong.getMode(),zhongReq.getType());
        Map<String, String> map = null;
        try{
            map = helperZhong.vipHeader(zhongSessionUser, zhongReq);
        }catch (Exception e){
            log.error("",e);
            //
        }
        int type = CollUtil.isEmpty(map)?0:1;
        //redisHelper.increase(helperZhong.getMode(),type);
        ZyantExceptionUtils.x(type==0,"授权异常，请稍后再试-"+helperZhong.getMode());
        String reqType = zhongReq.getType();
        if(!"newCallAndFile".equalsIgnoreCase(reqType)){
            return ZhongRes.ok(map);
        }
        ThreadPoolUtils.submitTask(()->{
            //更新列表，不再预约
            Integer autoStatus = zhongSessionUser.getAutoStatus();
            String account = zhongSessionUser.getAccount();
            //手动预约了
            String waybillNo = zhongReq.getWaybillNo();
            if(Objects.equals(reqType,"newCallAndFile")&&StrUtils.isNotBlank(waybillNo)&&Objects.equals(autoStatus,1)){
                String user_key = CommonUtil.yuyueRedisKey(account);
                redisLocker.updateLockTime(user_key,60 );
                String key = CommonUtil.waybillRedisListKey(zhongSessionUser.getAccount());
                //手动预约了,从列表中移除
                stringRedisTemplate.opsForZSet().remove(key,waybillNo);
            }
        });

        return ZhongRes.ok(map);

    }

    //过期检查 已过期返回ture
    private static boolean checkVip(LocalDateTime vipExpDate, Integer mode) {
        if(mode==1&& RehrsSystemConfig.isTest()){
            return false;
        }
        if(vipExpDate==null){
            return true;
        }
        return  vipExpDate.isBefore(LocalDateTime.now());
    }


    @ApiOperation(value = "5.1 further轨迹查询", httpMethod = "POST", notes = "5.1 further轨迹查询", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping({"further/traceInfo/query", "vip/traceInfo/query", "vip/trace/query"})
    //@Decrypt(value = false)
    public ZhongRes<TraceInfo> traceInfoQuery(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        ZhongUser zhongSessionUser = redisHelper.loadSessionUser(zhongReq.getToken(),true);
        if (zhongSessionUser==null) {
            return VarConstant.need_login_res;
        }
        Integer mode = zhongSessionUser.getMode();
        LocalDateTime vipExpDate = zhongSessionUser.getVipExpDate();
        if(checkVip(vipExpDate, mode)){
            return ZhongRes.fail("请先激活VIP");
        }
        String waybillNo = zhongReq.getWaybillNo();
        if(StrUtils.isBlank(waybillNo)||waybillNo.length()<10){
            return ZhongRes.fail("单号不正确");
        }
        if(ThreadLocalSession.isMode(1)){
            return helperDaxiang.queryTraceRes(waybillNo);
        }
        ZhongUser byCache10Min = zhongYouManager.initTraceQueryInfo();
        if(byCache10Min==null){
            return ZhongRes.fail("暂时无法查询轨迹，请稍后再试");
        }
        JSONObject jsonObject = null;
        try{
            jsonObject = zhongYouManager.traceInfoQuery(byCache10Min, waybillNo);
        }catch (Exception e){
            if(e.getMessage().contains("查询无数据")){
                return ZhongRes.fail("查询无数据");
            }
            log.info("轨迹查询异常，{}",e.getMessage());
            return ZhongRes.fail("暂时无法查询轨迹，请稍后再试");
        }
        JSONArray traceInfos = Optional.ofNullable(jsonObject)
                        .map(o->o.getJSONObject("obj"))
                                .map(o->o.getJSONArray("traceInfo"))
                                        .orElse(null);
        TraceInfo traceInfo = new TraceInfo();
        List<TraceInfoItem> traceInfoItemList = new ArrayList<>();
        traceInfo.setTraceInfoItemList(traceInfoItemList);
        for (int i = traceInfos.size() - 1; i >= 0; i--) {
            JSONObject item = (JSONObject)traceInfos.get(i);
            String weight = traceInfo.getWeight();
            if(StrUtils.isBlank(weight)){
                traceInfo.setWeight(item.getString("weight"));
            }
            String postagePaid = traceInfo.getPostagePaid();
            if(StrUtils.isBlank(postagePaid)){
                traceInfo.setPostagePaid(item.getString("postagePaid"));
            }
            String receiverLinker = traceInfo.getReceiverLinker();
            if(StrUtils.isBlank(receiverLinker)){
                traceInfo.setReceiverLinker(item.getString("receiverLinker"));
            }
            String receiverAddress = traceInfo.getReceiverAddress();
            if(StrUtils.isBlank(receiverAddress)){
                traceInfo.setReceiverAddress(item.getString("receiverAddress"));
            }
            TraceInfoItem javaObject = item.toJavaObject(TraceInfoItem.class);

            String notes = item.getString("notes");
            if(StrUtils.isNotBlank(notes)){
                javaObject.setOpName(javaObject.getOpName()+"("+ notes+")");
            }
            traceInfoItemList.add(javaObject);

        }

        return ZhongRes.ok(traceInfo);


    }

    @ApiOperation(value = "5.2 开启自动预约，autoStatus：0关闭 1开启", httpMethod = "POST", notes = "5.2 开启自动预约，autoStatus：0关闭 1开启", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("auto/status/setting")
    public ZhongRes autoStatusSet(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        ZhongUser zhongUser = redisHelper.loadSessionUser(zhongReq.getToken(),true);
        if (zhongUser==null) {
            return VarConstant.need_login_res;
        }
        Integer autoStatus = zhongReq.getAutoStatus();
        Integer autoTaskType = zhongReq.getAutoTaskType();
        if(autoStatus==null){
            return ZhongRes.fail("autoStatus or autoTaskType is null");
        }
        if(autoStatus==1&&autoTaskType==null){
            return ZhongRes.fail("autoStatus or autoTaskType is null");
        }
        if(autoStatus==1){
            int count = zhongUserImageService.count(zhongUserImageService.getQueryWrapper()
                    .eq(ZhongUserImage::getAccount, zhongUser.getAccount()));
            if(count==0){
                return ZhongRes.fail("操作失败，请联系客服先完成登记");
            }
        }
        if(autoStatus==0){
            autoTaskType = 0;
        }
        if(autoStatus>1||autoStatus<0||autoTaskType>2||autoTaskType<0){
            return ZhongRes.fail("autoStatus or autoTaskType is error");
        }
        LambdaUpdateWrapper<ZhongUser> zhongUserLambdaUpdateWrapper = zhongUserService.getUpdateWrapper().eq(ZhongUser::getId, zhongUser.getId())
                .set(ZhongUser::getAutoStatus, autoStatus)
                .set(autoTaskType!=null&&autoTaskType>0,ZhongUser::getAutoTaskType,autoTaskType)
                ;
        zhongUserService.update(zhongUserLambdaUpdateWrapper);
        if(autoStatus!=null){
            zhongUser.setAutoTaskType(autoTaskType);
        }
        zhongUser.setAutoStatus(autoStatus);
        redisHelper.saveSessionUser(zhongUser,true);
        ZhongRes ok = ZhongRes.ok();
        ok.setMsg(CommonUtil.buildTaskType(autoStatus,autoTaskType));
        return ok;

    }

    //1.2.6之前的版本
    @ApiOperation(value = "5.1 开启自动预约，autoStatus：0关闭 1开启，1.2.6之前的版本", httpMethod = "POST", notes = "5.1 开启自动预约，autoStatus：0关闭 1开启，1.2.6之前的版本", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("auto/status")
    public ZhongRes<Integer> autoStatus(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        return VarConstant.need_update_res;
    }


    @ApiOperation(value = "6.0 登录用户信息", httpMethod = "POST", notes = "6.0 登录用户信息", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("member/info")
    public ZhongRes<ZhongUser> sessionUser(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        ZhongUser zhongUser = redisHelper.loadSessionUser(zhongReq.getToken(),true);
        if (zhongUser==null) {
            return VarConstant.need_login_res;
        }
        reduce(zhongUser);
        LocalDateTime vipExpDate = zhongUser.getVipExpDate();
        String sAuth = "";
        if(vipExpDate!=null&&vipExpDate.isAfter(LocalDateTime.now())){
            sAuth = limitHelper.getSAuth(zhongUser.getAccount(),0);
        }
        ((MyZhongUser)zhongUser).setSauth(sAuth);
        return ZhongRes.ok(zhongUser);
    }

    private void reduce(ZhongUser zhongUser) {
        zhongUser.setInitIp(null);
        zhongUser.setPadId(null);
        zhongUser.setOrgLatitude(null);
        zhongUser.setOrgLongitude(null);
        zhongUser.setAndroidId(null);
        zhongUser.setImei(null);
        LocalDateTime vipExpDate = zhongUser.getVipExpDate();
        LocalDateTime now = LocalDateTime.now();
        if(vipExpDate==null){
            vipExpDate = now;
        }
        int dayDiff = DateUtils.getDayDiff(now, vipExpDate);
        if(dayDiff<0){
            dayDiff = 0;
        }
        String vipExpDateStr = "已到期";
        if(zhongUser.getVipExpDate()!=null&&zhongUser.getVipExpDate().isAfter(LocalDateTime.now())){
            vipExpDateStr = DateUtils.dateTimeToStr(zhongUser.getVipExpDate(), DateUtils.CH_TIME)+"到期";//"还有"+DateUtils.getDayDiff(LocalDateTime.now(), smUserInfo.getVipExpDate())+"天到期";
        }
        zhongUser.setVipExpDateStr(vipExpDateStr);
        zhongUser.setDays(dayDiff);
        if(!Objects.equals(zhongUser.getMode(),1)){
            zhongUser.setUserCode("");
        }

    }

    @ApiOperation(value = "6.1 VIP续费", httpMethod = "POST", notes = "6.1 VIP续费", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("member/recharge")
    public ZhongRes<ZhongUser> recharge(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        String token = zhongReq.getToken();
        if(StrUtils.isBlank(token)){
            return ZhongRes.fail("");
        }
        ZhongUser zhongUser = redisHelper.loadSessionUser(token,true);
        if (zhongUser==null) {
            return VarConstant.need_login_res;
        }
        String card = zhongReq.getCard();

        if(StrUtils.isBlank(card)){
            return ZhongRes.fail("");
        }
        ZhongRes<ZhongUser> zhongUserZhongRes = null;
        if(card.length()==14){
            zhongUserZhongRes = charge(zhongReq,zhongUser);
        }else {
            return ZhongRes.fail("");
        }
        ZhongUser obj = zhongUserZhongRes.getObj();
        if(!zhongUserZhongRes.isOK()){
            return zhongUserZhongRes;
        }
        reduce(obj);
        String sAuth = limitHelper.getSAuth(obj.getAccount(),0);
        if(zhongUser instanceof  MyZhongUser){
            MyZhongUser myZhongUser = (MyZhongUser) zhongUser;
            myZhongUser.setSauth(sAuth);
        }else  if(zhongUser instanceof SmZhongUser){
            SmZhongUser smZhongUser = (SmZhongUser) zhongUser;
            smZhongUser.setVipAuth(sAuth);
        }
        return zhongUserZhongRes;

    }




    public ZhongRes<ZhongUser> charge(ZhongReq zhongReq,ZhongUser zhongUser){
        String card = zhongReq.getCard();
        RechargeCard one = rechargeCardService.getOne(card);
        if(one==null||one.getUsedStatus().equals(1)){
            return ZhongRes.fail("卡密无效或者已经使用");
        }
        String token = zhongReq.getToken();
        String account = zhongUser.getAccount();
        zhongUser = zhongUserService.one(account);
        zhongUser.setToken(token);
        int exchange = rechargeCardService.exchange(one, zhongUser);
        if(exchange==0){
            return ZhongRes.fail("卡密无效或者已经使用");
        }
        if(exchange==2){
            return ZhongRes.fail("该账号已试用，无法再次试用");
        }
        redisHelper.saveSessionUser(zhongUser,true);
        return ZhongRes.ok(zhongUser);
    }


    @ApiOperation(value = "7.0 版本检测更新", httpMethod = "POST", notes = "7.0 版本检测更新", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("check/update")
    public ZhongRes<AppConfig> checkUpdate(@PathVariable String version) {
        Integer integer = Integer.valueOf(version);
        AppConfig appConfig = redisHelper.loadAppConfig(integer);
        return ZhongRes.ok(appConfig);
        //return ZhongRes.ok(null);

    }


    @ApiOperation(value = "8.0 通知公告", httpMethod = "POST", notes = "8.0 通知公告", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping("notice")
    public ZhongRes<NoticeMessage> msg(@PathVariable String version, @RequestBody() ZhongReq zhongReq) {
        String token = zhongReq.getToken();
        String account = zhongReq.getAccount();
        ZhongUser zhongSessionUser = null;
        if(StrUtils.isNotBlank(token)){
            zhongSessionUser  = redisHelper.loadSessionUser(token,true);
            account = zhongSessionUser.getAccount();
        }
        if(StrUtils.isNotBlank(account)){
            String key = "notice:account:"+account;
            boolean success = redisLocker.tryLock(key, 3600, String.valueOf(1));
            if(!success){
                return ZhongRes.ok();
            }
        }
        if(zhongSessionUser==null&&StrUtils.isNotBlank(account)){
            zhongSessionUser = zhongUserService.one(account);
        }
        List<String> msgList = new ArrayList<>();
        if(zhongSessionUser!=null){
            //有账号
            LocalDateTime vipExpDate = zhongSessionUser.getVipExpDate();
            Integer autoStatus = zhongSessionUser.getAutoStatus();
            int hourDiff = DateUtils.getHourDiff(LocalDateTime.now(),vipExpDate);
            if (hourDiff>0&&hourDiff<23){
                msgList.add("账号VIP时间一天内将到期");
            }
            if(hourDiff>0){
                String msg = "已开启自动预约功能";
                if(!Objects.equals(autoStatus,1)){
                    msg = "未开启自动预约功能，需要手动预约";
                }
                msgList.add(msg);
            }
        }
        String userAgent = WebUtils.getRequest().getHeader("user_agent");
        String hello_key = MD5.encode(userAgent+WebUtils.getIpAddress());
        hello_key = "notice:hello:"+account+":"+hello_key;
        boolean success = redisLocker.tryLock(hello_key, 3600 * 8, String.valueOf(1));
        if(success){
            msgList.add("客服QQ1111111111");
        }
        if(msgList.size()==0){
            return ZhongRes.ok();
        }
        NoticeMessage noticeMessage = new NoticeMessage();
        noticeMessage.setContents(msgList);
        noticeMessage.setTitle("欢迎回来");
        return ZhongRes.ok(noticeMessage);

    }

}
